//
//  GuideCollectionViewCell.m
//  BeautifulShoppings
//
//  Created by GivenBmli on 16/9/13.
//  Copyright © 2016年 GivenBmli. All rights reserved.
//

#import "GuideCollectionViewCell.h"
#import "GuideTableViewCell.h"
#import "GuideModel.h"
#import "GuideTableViewCell.h"
#import "GuideViewController.h"
#import "UIImageView+WebCache.h"
#import "TAMacro.h"
@implementation GuideCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [SVProgressHUD show];
        [self creatTabView:frame];
        [SVProgressHUD dismiss];
    }
    return self;
}
- (NSMutableArray *)array {
    if (!_array) {
        self.array = [NSMutableArray array];
    }
    return _array;
}
- (void)creatTabView:(CGRect)frame {
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height-108) style:0];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.contentView addSubview:self.tableView];
    
}
- (void)setArrayModels:(NSMutableArray *)arrayModels {
    if (_arrayModels != arrayModels) {

    }
    [self.tableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    return self.arrayModels.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return SCREEN_WIDTH / 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *ID = @"cell";
    self.cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (self.cell  == nil) {
        self.cell = [[GuideTableViewCell alloc]initWithStyle:0 reuseIdentifier:ID];
    }
    if (self.arrayModels.count != 0) {
        GuideModel *model = self.arrayModels[indexPath.row];
        self.cell.title.text = model.title;
        [self.cell.cover_image_url sd_setImageWithURL:[NSURL URLWithString:model.cover_image_url]placeholderImage:[UIImage imageNamed:@"站位"]];
        [self.cell jxl_setDayMode:^(UIView *view) {
            self.cell.backgroundColor = [UIColor whiteColor];
        } nightMode:^(UIView *view) {
            self.cell.backgroundColor = [UIColor grayColor];
        }];
    }
    return self.cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.arrayModels.count != 0) {
        GuideModel *model = self.arrayModels[indexPath.row];
        self.str = [NSString stringWithFormat:@"%ld",(long)model.Id];
        self.STR = model.title;
        self.Image = model.cover_image_url;
    }
    [self.delegate didClickSelectItemAtIndexPathGuide:indexPath str:self.str STR:self.STR Image:self.Image];
    
}
@end
